package cn.edu.lingnan.controller;

import cn.edu.lingnan.pojo.Student;
import cn.edu.lingnan.service.StudentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

@Controller
@RequestMapping("/student")
public class StudentController {

    @Autowired
    @Qualifier("studentService")
    private StudentService studentService;


//    @RequestMapping("/login")
//    public String login(String sname, String password) {
//        System.out.println(sname + "NNNNN" + password);
//        Student student = studentService.selectStudentByNameAndPassword(sname, password);
//        if (student != null)
//            return "home";
//        else
//            return "redirect:/index.html";
//    }

    @RequestMapping("/insertStudent")
    public String insertStudent(Student student) {
        studentService.insertStudent(student);
        return "redirect:/index.html";
    }

    @RequestMapping("/selectStudentAll")
    public String selectStudentAll(Model model) {
        model.addAttribute("allStu", studentService.selectStudentAll());
        return "admin/allStudent";//返回到allStudent这个页面
    }

    @RequestMapping("/updateStudent")
    public String updateStudent(Student student) {
        studentService.updateStudent(student);
        return "redirect:/student/selectStudentAll";
    }

    @RequestMapping("/toUpdateStudent")
    public String toUpdateStudent(int sid, Model model) {
        model.addAttribute("stu",studentService.selectStudentBySid(sid));
        return "/admin/updateStudent";


    }
}
